//
//  Locale.swift
//  Documentation
//
//  Created by Toj on 11/13/23.
//

/**
 * Locale封装了有关语言、文化、技术惯例和标准的信息.
 * Locale封装的信息示例包括用于数字的小数点、分隔符和日期格式化符号等.
 * 尽管可以使用多种语言环境, 但通常使用与当前用户关联的语言环境
*/
public struct Locale : Hashable, Equatable, ReferenceConvertible, Sendable {

    public typealias ReferenceType = NSLocale

    public typealias LanguageDirection = NSLocale.LanguageDirection

    /// 返回跟踪用户当前偏好的区域设置
    /// 如果发生改变, 这个Locale将不再跟踪用户的首选项.
    /// NOTE:自动更新区域只会与另一个自动更新区域进行比较.
    public static var autoupdatingCurrent: Locale { get }

    /// 返回用户的当前Locale.
    public static var current: Locale { get }

    /// 初始化
    public init(identifier: String)

    /// 本地化标识符.
    public func localizedString(forIdentifier identifier: String) -> String?

    /// 本地化语言代码
    public func localizedString(forLanguageCode languageCode: String) -> String?

    /// 本地化地区代码
    ///
    /// For example, in the "en" locale, the result for `"fr"` is `"France"`.
    public func localizedString(forRegionCode regionCode: String) -> String?

    /// 本地化脚本代码
    public func localizedString(forScriptCode scriptCode: String) -> String?

    /// 本地化变体代码
    ///
    /// For example, in the "en" locale, the result for `"POSIX"` is `"Computer"`.
    public func localizedString(forVariantCode variantCode: String) -> String?

    /// 本地化日历标识符
    ///
    /// For example, in the "en" locale, the result for `.buddhist` is `"Buddhist Calendar"`.
    public func localizedString(for calendarIdentifier: Calendar.Identifier) -> String?
    public enum Identifier {
            case gregorian//公历
            case buddhist//佛历
            case chinese//农历
            case coptic//科普特历
            case ethiopicAmeteMihret//埃塞俄比亚历
            case ethiopicAmeteAlem//埃塞俄比亚阿米特阿莱姆日历
            case hebrew//希伯来历
            case iso8601//国际标准历法
            case indian//印度国定历
            case islamic//伊斯兰历
            case islamicCivil//伊斯兰希吉来日历
            case japanese//和历
            case persian//波斯历
            case republicOfChina//民国纪年
            case islamicTabular//伊斯兰天文历
            case islamicUmmAlQura//伊斯兰历（乌姆库拉）
    }
    
    /// 本地化货币代码
    ///
    /// For example, in the "en" locale, the result for `"USD"` is `"US Dollar"`.
    /// - seealso: `Locale.isoCurrencyCodes`
    public func localizedString(forCurrencyCode currencyCode: String) -> String?

    /// 本地化排序标识符
    ///
    /// For example, in the "en" locale, the result for `"phonebook"` is `"Phonebook Sort Order"`.
    public func localizedString(forCollationIdentifier collationIdentifier: String) -> String?

    /// Returns a localized string for a specified ICU collator identifier.
    public func localizedString(forCollatorIdentifier collatorIdentifier: String) -> String?

    /// locale的标识符
    public var identifier: String { get }

    /// locale的语言代码
    ///
    /// For example, for the locale "zh-Hant-HK", returns "zh".
    @available(macOS, deprecated: 13, renamed: "language.languageCode.identifier")
    @available(iOS, deprecated: 16, renamed: "language.languageCode.identifier")
    @available(tvOS, deprecated: 16, renamed: "language.languageCode.identifier")
    @available(watchOS, deprecated: 9, renamed: "language.languageCode.identifier")
    public var languageCode: String? { get }

    /// locale的地区代码
    ///
    /// For example, for the locale "zh-Hant-HK", returns "HK".
    @available(macOS, deprecated: 13, renamed: "language.region.identifier")
    @available(iOS, deprecated: 16, renamed: "language.region.identifier")
    @available(tvOS, deprecated: 16, renamed: "language.region.identifier")
    @available(watchOS, deprecated: 9, renamed: "language.region.identifier")
    public var regionCode: String? { get }

    /// locale的脚本代码
    ///
    /// For example, for the locale "zh-Hant-HK", returns "Hant".
    @available(macOS, deprecated: 13, renamed: "language.script.identifier")
    @available(iOS, deprecated: 16, renamed: "language.script.identifier")
    @available(tvOS, deprecated: 16, renamed: "language.script.identifier")
    @available(watchOS, deprecated: 9, renamed: "language.script.identifier")
    public var scriptCode: String? { get }

    /// locale的变体代码
    ///
    /// For example, for the locale "en_POSIX", returns "POSIX".
    @available(macOS, deprecated: 13, renamed: "variant.identifier")
    @available(iOS, deprecated: 16, renamed: "variant.identifier")
    @available(tvOS, deprecated: 16, renamed: "variant.identifier")
    @available(watchOS, deprecated: 9, renamed: "variant.identifier")
    public var variantCode: String? { get }

    /// locale的范例字符集
    public var exemplarCharacterSet: CharacterSet? { get }

    /// locale的日历
    public var calendar: Calendar { get }

    /// locale的排序规则标识符
    ///
    /// For example, for the locale "en_US@collation=phonebook", returns "phonebook".
    @available(macOS, deprecated: 13, renamed: "collation.identifier")
    @available(iOS, deprecated: 16, renamed: "collation.identifier")
    @available(tvOS, deprecated: 16, renamed: "collation.identifier")
    @available(watchOS, deprecated: 9, renamed: "collation.identifier")
    public var collationIdentifier: String? { get }

    /// locale是否使用公制
    ///
    /// -seealso: MeasurementFormatter
    @available(macOS, deprecated: 13, message: "Use `measurementSystem` instead")
    @available(iOS, deprecated: 16, message: "Use `measurementSystem` instead")
    @available(tvOS, deprecated: 16, message: "Use `measurementSystem` instead")
    @available(watchOS, deprecated: 9, message: "Use `measurementSystem` instead")
    public var usesMetricSystem: Bool { get }

    /// locale的小数分隔符
    ///
    /// For example, for "en_US", returns ".".
    public var decimalSeparator: String? { get }

    /// locale的分组分隔符
    ///
    /// For example, for "en_US", returns ",".
    public var groupingSeparator: String? { get }

    /// locale的货币符号
    ///
    /// For example, for "zh-Hant-HK", returns "HK$".
    public var currencySymbol: String? { get }

    /// locale的货币代码
    ///
    /// For example, for "zh-Hant-HK", returns "HKD".
    @available(macOS, deprecated: 13, renamed: "currency.identifier")
    @available(iOS, deprecated: 16, renamed: "currency.identifier")
    @available(tvOS, deprecated: 16, renamed: "currency.identifier")
    @available(watchOS, deprecated: 9, renamed: "currency.identifier")
    public var currencyCode: String? { get }

    /// locale的排序器标识符
    public var collatorIdentifier: String? { get }

    /// locale的引号开始定界符
    ///
    /// For example, returns `“` for "en_US", and `「` for "zh-Hant-HK".
    public var quotationBeginDelimiter: String? { get }

    /// locale的引号结尾定界符
    ///
    /// For example, returns `”` for "en_US", and `」` for "zh-Hant-HK".
    public var quotationEndDelimiter: String? { get }

    /// locale的备用引号开始定界符
    ///
    /// For example, returns `‘` for "en_US", and `『` for "zh-Hant-HK".
    public var alternateQuotationBeginDelimiter: String? { get }

    /// locale的备用引号结尾定界符
    ///
    /// For example, returns `’` for "en_US", and `』` for "zh-Hant-HK".
    public var alternateQuotationEndDelimiter: String? { get }

    /// Returns a list of available `Locale` identifiers.
    /// 可通过availableIdentifiers变量获取可用的标识符。
    public static var availableIdentifiers: [String] { get }

    /// Returns a list of available `Locale` language codes.
    /// 语言代码为zh_Hans_CN前面的zh，可通过isoLanguageCodes变量获取可用的语言代码。
    @available(macOS, deprecated: 13, message: "Use `Locale.LanguageCode.isoLanguageCodes` instead")
    @available(iOS, deprecated: 16, message: "Use `Locale.LanguageCode.isoLanguageCodes` instead")
    @available(tvOS, deprecated: 16, message: "Use `Locale.LanguageCode.isoLanguageCodes` instead")
    @available(watchOS, deprecated: 9, message: "Use `Locale.LanguageCode.isoLanguageCodes` instead")
    public static var isoLanguageCodes: [String] { get }

    /// Returns a list of available `Locale` region codes.
    /// 地区代码为zh_Hans_CN后面的CN，可通过isoRegionCodes变量获取可用的地区代码。
    @available(macOS, deprecated: 13, message: "Use `Locale.Region.isoRegions` instead")
    @available(iOS, deprecated: 16, message: "Use `Locale.Region.isoRegions` instead")
    @available(tvOS, deprecated: 16, message: "Use `Locale.Region.isoRegions` instead")
    @available(watchOS, deprecated: 9, message: "Use `Locale.Region.isoRegions` instead")
    public static var isoRegionCodes: [String] { get }

    /// 返回可用的'Locale'货币代码列表
    @available(macOS, deprecated: 13, message: "Use `Locale.Currency.isoCurrencies` instead")
    @available(iOS, deprecated: 16, message: "Use `Locale.Currency.isoCurrencies` instead")
    @available(tvOS, deprecated: 16, message: "Use `Locale.Currency.isoCurrencies` instead")
    @available(watchOS, deprecated: 9, message: "Use `Locale.Currency.isoCurrencies` instead")
    public static var isoCurrencyCodes: [String] { get }

    /// 可通过commonISOCurrencyCodes变量获取通用的货币代码.
    public static var commonISOCurrencyCodes: [String] { get }

    /// 获取用户的首选语言列表
    public static var preferredLanguages: [String] { get }

    /// 将标识符转换成组件字典
    @available(macOS, deprecated: 13, message: "Use `Locale.Components(identifier:)` to access components")
    @available(iOS, deprecated: 16, message: "Use `Locale.Components(identifier:)` to access components")
    @available(tvOS, deprecated: 16, message: "Use `Locale.Components(identifier:)` to access components")
    @available(watchOS, deprecated: 9, message: "Use `Locale.Components(identifier:)` to access components")
    public static func components(fromIdentifier string: String) -> [String : String]

    /// 将组件字典转换成标识符
    public static func identifier(fromComponents components: [String : String]) -> String

    /// Returns a canonical identifier from the given string.
    @available(*, deprecated, renamed: "identifier(_:from:)")
    @available(macOS, deprecated: 13, renamed: "identifier(_:from:)")
    @available(iOS, deprecated: 16, renamed: "identifier(_:from:)")
    @available(tvOS, deprecated: 16, renamed: "identifier(_:from:)")
    @available(watchOS, deprecated: 9, renamed: "identifier(_:from:)")
    public static func canonicalIdentifier(from string: String) -> String

    /// 将字符串转换成规范的语言标识符
    public static func canonicalLanguageIdentifier(from string: String) -> String

    /// 将Windows的语言环境代码转换成标识符
    public static func identifier(fromWindowsLocaleCode code: Int) -> String?

    /// 将标识符转换成Windows的语言环境代码
    public static func windowsLocaleCode(fromIdentifier identifier: String) -> Int?

    /// 返回指定语言代码的字符方向.
    @available(macOS, deprecated: 13, message: "Use `Locale.Language(identifier:).characterDirection`")
    @available(iOS, deprecated: 16, message: "Use `Locale.Language(identifier:).characterDirection`")
    @available(tvOS, deprecated: 16, message: "Use `Locale.Language(identifier:).characterDirection`")
    @available(watchOS, deprecated: 9, message: "Use `Locale.Language(identifier:).characterDirection`")
    public static func characterDirection(forLanguage isoLangCode: String) -> Locale.LanguageDirection

    /// 返回指定语言代码的行方向.
    @available(macOS, deprecated: 13, message: "Use `Locale.Language(identifier:).lineLayoutDirection`")
    @available(iOS, deprecated: 16, message: "Use `Locale.Language(identifier:).lineLayoutDirection`")
    @available(tvOS, deprecated: 16, message: "Use `Locale.Language(identifier:).lineLayoutDirection`")
    @available(watchOS, deprecated: 9, message: "Use `Locale.Language(identifier:).lineLayoutDirection`")
    public static func lineDirection(forLanguage isoLangCode: String) -> Locale.LanguageDirection

    public func hash(into hasher: inout Hasher)
    public static func == (lhs: Locale, rhs: Locale) -> Bool
    public var hashValue: Int { get }
}

public enum LanguageDirection : UInt {
        case unknown = 0//未知
        case leftToRight = 1//从左到右
        case rightToLeft = 2//从右到左
        case topToBottom = 3//从上到下
        case bottomToTop = 4//从下到上
}
